GBML manual / Collision

mask_sprite

Takes this instance’s collision-box SIZE (not its pixels - S2.6: "collision masks are rectangles") from another sprite’s size instead of `sprite`’s own. Outranked per axis by `mask_w`/`mask_h`; leave all of them unset to use `sprite`’s size.

Syntax

mask_sprite: sprite

Description

Takes this instance's collision box size from another sprite's size, instead of from its own sprite.

Only the size is read. The sprite named here is never drawn, and nothing ever asks what color its pixels are - a collision mask is a rectangle, always.

Example

mask_sprite = spr_doc_footprint;

This instance now collides as whatever spr_doc_footprint is drawn at, however big its own art is.

It is outranked by the numbers, per axis

mask_w and mask_h give a mask any size at all. When one of them is set it wins for that axis; when it is left at 0, that axis falls back here, and then to sprite.

So the full order, for each axis on its own:

SettingWhat decides that axis
mask_w/mask_h above 0that number
otherwise, mask_sprite setthat sprite's size
otherwise, sprite setthat sprite's size
otherwise0 - a box with no size, a single point

An instance with no sprite and no mask has a box with no size: a point at its x and y. A box meets that point only when the point is strictly inside it, never on an edge or a corner, and two boxes with no size never meet; collision_point, point_meeting, collision_line and collision_circle never find it, and tile_free calls it free everywhere (Overlap and collision has the whole rule). A purely logical object - a controller, a timer, a spawner - is therefore out of the way of every question that names another object, without having to say so.

When to reach for this rather than a number

Two cases, and they are narrower than they used to be.

For everything else, prefer the numbers - because a sprite can only ever be 8, 16, 32 or 64 pixels per axis. Those are the sizes the console's sprite hardware has, and there is nothing in between. An 18-pixel box is not awkward to ask for this way; it cannot be asked for at all. Neither can a box bigger than the art, unless you draw a bigger picture and never show it.

That limit is a fact about drawing, and a mask is never drawn. mask_w and mask_h are free of it.

It cannot move the box

This sets a size and nothing else - the box stays centered on the instance. Use mask_x and mask_y to move it; they apply whichever way the size was decided.

On the GBA

A sprite is 8, 16, 32 or 64 pixels per axis and nothing else, so this form can only ever ask for one of those four sizes - a hardware fact about DRAWING reaching a question that never draws anything (a mask is never drawn; only its size is read). mask_w/mask_h are free of it. Reach for this one when an art asset genuinely defines the shape and should keep defining it when that asset is redrawn.

See also: mask_wmask_hmask_xmask_ybox_leftcollides